package com.hzlx.materials.controller;

import java.util.List;
import java.io.IOException;

import com.hzlx.MesMaterialBatchesDto;
import com.hzlx.MesMaterialsDto;
import com.hzlx.mesMaterialBatches.domain.MesMaterialBatches;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hzlx.materials.domain.MesMaterials;
import com.hzlx.materials.service.IMesMaterialsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * MES物料详细信息Controller
 * 
 * @author ruoyi
 * @date 2025-07-01
 */
@RestController
@RequestMapping("/inventory")
public class MesMaterialsController extends BaseController
{
    @Autowired
    private IMesMaterialsService mesMaterialsService;

    /**
     * 查询MES物料详细信息列表
     */
    @RequiresPermissions("material-service:inventory:materials:list")
    @GetMapping("/materials/list")
    public TableDataInfo list(MesMaterials mesMaterials)
    {
        startPage();
        List<MesMaterials> list = mesMaterialsService.selectMesMaterialsList(mesMaterials);
        return getDataTable(list);
    }
    /**
     * 导出MES物料详细信息列表
     */
    @RequiresPermissions("material-service:inventory:materials:export")
    @Log(title = "MES物料详细信息", businessType = BusinessType.EXPORT)
    @PostMapping("/materials/export")
    public void export(HttpServletResponse response, MesMaterials mesMaterials)
    {
        List<MesMaterials> list = mesMaterialsService.selectMesMaterialsList(mesMaterials);
        ExcelUtil<MesMaterials> util = new ExcelUtil<MesMaterials>(MesMaterials.class);
        util.exportExcel(response, list, "MES物料详细信息数据");
    }

    /**
     * 获取MES物料详细信息详细信息
     */
    @RequiresPermissions("material-service:inventory:materials:query")
    @GetMapping(value = "/materials/{materialId}")
    public AjaxResult getInfo(@PathVariable("materialId") Long materialId)
    {
        return success(mesMaterialsService.selectMesMaterialsByMaterialId(materialId));
    }

    /**
     * 新增MES物料详细信息
     */
    @RequiresPermissions("material-service:inventory:materials:add")
    @Log(title = "MES物料详细信息", businessType = BusinessType.INSERT)
    @PostMapping("/materials")
    public AjaxResult add(@RequestBody MesMaterials mesMaterials)
    {
        return toAjax(mesMaterialsService.insertMesMaterials(mesMaterials));
    }

    /**
     * 修改MES物料详细信息
     */
    @RequiresPermissions("material-service:inventory:materials:edit")
    @Log(title = "MES物料详细信息", businessType = BusinessType.UPDATE)
    @PutMapping("/materials")
    public AjaxResult edit(@RequestBody MesMaterials mesMaterials)
    {
        return toAjax(mesMaterialsService.updateMesMaterials(mesMaterials));
    }
    /**
     * 删除MES物料详细信息
     */
    @RequiresPermissions("material-service:inventory:materials:remove")
    @Log(title = "MES物料详细信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/materials/{materialIds}")
    public AjaxResult remove(@PathVariable Long[] materialIds)
    {
        return toAjax(mesMaterialsService.deleteMesMaterialsByMaterialIds(materialIds));
    }
}
